<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: products_parameters.php 102 2013-09-21 12:06:39Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 102 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:06:39 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');
switch ($_GET['action']) {
  case 'insert':
    $name = $_POST['name'];
    $sort_order = $_POST['sort_order'];
    $db->db_query("INSERT INTO ".TABLE_PRODUCTS_PARAMETERS_GROUPS." (sort_order) VALUES (".$sort_order.")");
    $insert_id = $db->db_insert_id();
    foreach($name as $key=>$value) {
      $db->db_query("INSERT INTO ".TABLE_PRODUCTS_PARAMETERS_GROUPS_DESCRIPTION." (group_id, language_id, group_name) VALUES (".$insert_id.", ".$key.", '".$value."')");
    }
	redirect(href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page']). '&products_id='.$_GET['products_id']);
    break;

  case 'save':
    $gID = $_GET['gID'];
    $name = $_POST['name'];
	$sort_order = $_POST['sort_order'];

    $db->db_query("UPDATE ".TABLE_PRODUCTS_PARAMETERS_GROUPS." SET sort_order = ".$db->db_prepare($sort_order)." WHERE group_id = '".$gID."'");
    foreach($name as $key=>$value) {
      $db->db_query("UPDATE ".TABLE_PRODUCTS_PARAMETERS_GROUPS_DESCRIPTION." SET group_name = ".$db->db_prepare($value)." WHERE group_id = '".$gID."' AND language_id=".$key);
    }
    redirect(href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'].'&gID='.$_GET['gID']));
    break;

  case 'deleteconfirm':
    $gID = $_GET['gID'];
    $db->db_query("DELETE FROM ".TABLE_PRODUCTS_PARAMETERS_GROUPS." WHERE group_id = ".$db->db_prepare($gID)."");
    $db->db_query("DELETE FROM ".TABLE_PRODUCTS_PARAMETERS_GROUPS_DESCRIPTION." WHERE group_id = ".$db->db_prepare($gID)."");
    redirect(href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page']).'&products_id='.$_GET['products_id']);
    break;

  case 'delete':
    break;
}
require(DIR_WS_INCLUDES.'metatag.php');
if($_GET['action'] == 'new') {
?>
<script type="text/javascript">
	<!--
		function checkIt(form){
			if (form.sort_order.value != 0)
				return true;
			else {
				alert('<?php echo CHOOSE_SORT_ORDER; ?>');
				return false;
			}
		}
	//-->
</script>
<?php } ?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
<table class="outerTable" cellspacing="0" cellpadding="0">
  <tr>
    <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
		<table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
			<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
    	</table>
	</td>
    <td class="boxCenter" valign="top">
	<table width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td width="100%">
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
          		<tr>
            		<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
          		</tr>
        	</table>
		</td>
      </tr>
	<tr>
		<td width="100%" align="right">
            <a class="button" href="categories.php?cPath=<?php echo $_GET['category_path']; ?>&pID=<?php echo $_GET['products_id']; ?>">zur&uuml;ck zum Produkt</a>
		</td>
	</tr>
	<td>
    <?php echo draw_form('search', FILENAME_PRODUCTS_PARAMETERS_EDIT, '', 'post').draw_hidden_field('products_id', $_GET['products_id']). draw_hidden_field('category_path', $_GET['category_path'])."\n"; ?>
      <table border="0" width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td valign="top">
            <table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent" width="1%"><?php echo TABLE_HEADING_SELECT; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PARAMETERS_NAME; ?> </td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_SORT_ORDER; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
				<?php
				$sql = "SELECT g.group_id, g.sort_order, gd.group_name FROM ".TABLE_PRODUCTS_PARAMETERS_GROUPS." g, ".TABLE_PRODUCTS_PARAMETERS_GROUPS_DESCRIPTION ." gd WHERE g.group_id=gd.group_id AND gd.language_id=".$_SESSION['languages_id']." ORDER BY g.sort_order";
				$query = page_break_create($_POST['per_site'], $_GET['page'], $sql, 'products_parameters.php');
				$groups = $query['query'];
				$languages = get_languages();
				while (!$groups->EOF) { 
					$rows++;
					if (((!$_GET['gID']) || (@$_GET['gID'] == $groups->fields['group_id'])) && (!$gInfo) && (substr($_GET['action'], 0, 3) != 'new')) {
						$gInfo = new objectInfo($groups->fields);
						$names = $db->db_query("SELECT group_name, language_id FROM ".TABLE_PRODUCTS_PARAMETERS_GROUPS_DESCRIPTION ." WHERE group_id=".$groups->fields['group_id']);
						$name = array();
						
						while (!$names->EOF) {
					  		$name[$names->fields['language_id']] = $names->fields['group_name'];
					  	$names->MoveNext();
						}
					}
				  $select_result = $db->db_query("SELECT COUNT(parameters_id) AS count FROM ".TABLE_PRODUCTS_PARAMETERS." WHERE group_id=".$groups->fields['group_id']." AND products_id=".$_GET['products_id']);
				  $selected = $select_result->fields['count']>0?true:false;
				  if((is_object($gInfo)) && ($groups->fields['group_id'] == $gInfo->group_id) ) {
				    echo '<tr class="dataTableRowSelected">'."\n";
				  } else {
					if ($rows % 2 == 0)
			    		$f = 'dataTableRow';
			    	else
			    		$f = '';
				    echo '<tr class="'.$f.'" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'pointer\'" onmouseout="this.className=\''.$f.'\'">'."\n";
				  }
				  echo '<td class="dataTableContent">'.draw_checkbox_field('sel[]', $groups->fields['group_id'], $selected).'</td>'."\n";
				  echo '<td class="dataTableContent">'.$groups->fields['group_name'].'</td>'."\n";
				?>
					<td class="dataTableContent"><?php echo $groups->fields['sort_order']; ?></td>
				 	<td class="dataTableContent" align="right">
						<?php
							if((is_object($gInfo)) && ($groups->fields['group_id'] == $gInfo->group_id) ) {
								echo image(DIR_WS_IMAGES.'icon_arrow_right.gif');
							} else {
								echo '<a href="'.href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'].'&gID='.$groups->fields['group_id']).'">'.image(DIR_WS_IMAGES.'icon_info.gif', IMAGE_ICON_INFO).'</a>&nbsp;';
								echo '<a href="'.href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'] .' &gID='.$groups->fields['group_id'].'&action=edit').'">'.image(DIR_WS_IMAGES.'icon_edit.gif').'</a>';
							}
						?>&nbsp;
					</td>
				</tr>
				<?php $groups->MoveNext(); } ?>
              <tr>
                <td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                		<tr class="page_break">
							<td class="smallText" valign="top" width="33.3%"><?php echo 'Angezeigt werden '.$query['from'].' bis '.$query['to'].' (von insgesamt '.$query['total'].' Artikeln)'; ?></td>
							<td class="smallText" align="center" width="33.3%"></td>
							<td class="smallText" align="right" width="33.3%">
								Produkte pro Seite: <?php echo $query['page_break']->perSiteDropdown($_GET['page']); ?>
							</td>
						</tr>
                </table></td>
              </tr>
            </table></form></td>
			<?php

			$heading = array();
			$contents = array();
			switch ($_GET['action']) {
			  case 'new':
			    $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_NEW_GROUP.'</b>');
			    $contents = array('form' => draw_form('languages', FILENAME_PRODUCTS_PARAMETERS, 'action=insert&products_id='.$_GET['products_id'],'POST','onsubmit="return checkIt(this);"'));
			    $contents[] = array('text' => TEXT_INFO_INSERT_INTRO);
			    for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			      $contents[] = array('text' => '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'] .'/admin/images/'. $languages[$i]['image'], $languages[$i]['name'])." ".TEXT_INFO_GROUP_NAME.'<br />'.draw_input_field('name['.$languages[$i]['id'].']'));
			    }
			    $contents[] = array('text' => '<br />'.TEXT_INFO_GROUP_SORT_ORDER.'<br />'.draw_input_field('sort_order'));
			    $contents[] = array('align' => 'center', 'text' => '<br /><button type="submit" class="button" onclick="this.blur();">'. BUTTON_INSERT.'</button> <a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'].'&gID='.$_GET['gID']).'">'.BUTTON_CANCEL.'</a>');
			    break;

			  case 'edit':
			    $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_EDIT_GROUP.'</b>');
			    $contents = array('form' => draw_form('languages', FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'].'&gID='.$gInfo->group_id.'&action=save'));
			    $contents[] = array('text' => TEXT_INFO_EDIT_INTRO);
			    for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			      $contents[] = array('text' => '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'] .'/admin/images/'. $languages[$i]['image'], $languages[$i]['name'])." ".TEXT_INFO_GROUP_NAME.'<br />'.draw_input_field('name['.$languages[$i]['id'].']', $name[$languages[$i]['id']]));
			    };
			    $contents[] = array('text' => '<br />'.TEXT_INFO_GROUP_SORT_ORDER.'<br />'.draw_input_field('sort_order', $gInfo->sort_order));
			    $contents[] = array('align' => 'center', 'text' => '<br /><button type="submit" class="button" onclick="this.blur();">'. BUTTON_UPDATE.'</button> <a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'].'&gID='.$gInfo->group_id).'">'.BUTTON_CANCEL.'</a>');
			    break;

			  case 'delete':
			    $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_DELETE_GROUP.'</b>');
			    $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
			    $contents[] = array('text' => '<br /><b>'.$gInfo->name.'</b>');
			    $contents[] = array('align' => 'center', 'text' => '<br />'.'<a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'].'&gID='.$gInfo->group_id.'&action=deleteconfirm').'">'.BUTTON_DELETE.'</a><a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'].'&gID='.$gInfo->group_id).'">'.BUTTON_CANCEL.'</a>');
			    break;

			  default:
			    if (is_object($gInfo)) {
			      $heading[] = array('text' => '<b>'.$gInfo->group_name.'</b>');
			      $contents[] = array('align' => 'center', 'text' => '<a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'].'&gID='.$gInfo->group_id.'&action=edit').'">'.BUTTON_EDIT.'</a> <a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'].'&gID='.$gInfo->group_id.'&action=delete').'">'.BUTTON_DELETE.'</a>');
			      for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			        $contents[] = array('text' => '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'] .'/admin/images/'. $languages[$i]['image'], $languages[$i]['name'])." ".TEXT_INFO_GROUP_NAME.$name[$languages[$i]['id']]);
			      };
			      $contents[] = array('text' => '<br />'.TEXT_INFO_GROUP_SORT_ORDER.' '.$gInfo->sort_order);
			    }
			    break;
			}

			if ((not_null($heading)) && (not_null($contents)) ) {
			  echo '            <td width="25%" valign="top">'."\n";
			  $box = new box;
			  echo $box->infoBox($heading, $contents);
			  echo '            </td>'."\n";
			}
			$parameters_page_dropdown = '<form name="anzahl" action="'.$_SERVER['REQUEST_URI'].'" method="GET">'. "\n";

			if($_GET['oID'] != '')
				$parameters_page_dropdown .= draw_hidden_field('oID', $_GET['oID']);
			if($_GET['page'] != '')
				$parameters_page_dropdown .= draw_hidden_field('page', $_GET['page'])."\n";

			$parameters_dropdown_options = Array();

			$parameters_dropdown_options[] = Array('id' => '10', 'text' => '10');
			$parameters_dropdown_options[] = Array('id' => '20', 'text' => '20');
			$parameters_dropdown_options[] = Array('id' => '50', 'text' => '50');
			$parameters_dropdown_options[] = Array('id' => '100', 'text' => '100');

			$parameters_page_dropdown .= draw_pull_down_menu('anzahl', $parameters_dropdown_options, ($_GET['anzahl'] != '' ? $_GET['anzahl'] : '20'), 'onchange="this.form.submit()"')."\n";

			$parameters_page_dropdown .= '</form>'."\n";
			?>
          	</tr>
			<tr>
				<td colspan="2">
					<table border="0" width="100%" cellspacing="0" cellpadding="2">
						<tr>
							<?php if (!$_GET['action']) { ?>
							<td>
								<input type="submit" class="button" onClick="this.blur();" value="<?php echo BUTTON_EDIT; ?>"/>
							</td>
							<td align="right">
								<?php echo '<a class="button" onClick="this.blur();" href="'.href_link(FILENAME_PRODUCTS_PARAMETERS, 'page='.$_GET['page'].'&products_id='.$_GET['products_id'].'&gID='.$gInfo->group_id.'&action=new').'">'.BUTTON_NEW_GROUP.'</a>'; ?>
							</td>
							<?php } ?>
						</tr>
					</table>
				</td>
			</tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
<br />
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>